<%--
  Created by IntelliJ IDEA.
  User: xindeyingzi
  Date: 2024/8/16
  Time: 19:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

        $.get("book/quryall", function (book) {
            JSON.stringify(book);
            forbooks(book);
        });

        $("[value='查询']").click(function () {
            var index = $("select").val();
            var val = $("[name='qval']").val();
            $.get("book/quryby", {"index": index, "val": val}, function (book) {
                forbooks(book);
            });

        });
    });
    $(document).on("click", "a[title='删除']", function () {
        var id = $(this).attr("name");

        $.get("book/delect", {"bid": id}, function (booksMess) {

            alert(booksMess.mess);
            var book = booksMess.pageHelper.list
            forbooks(book);
        });
    });
    $(document).on("click", "a[title='修改']", function () {
        var id = $(this).attr("name");
        window.location.href = "http://localhost:8080/update.jsp?bid=" + id;
    });

    function forbooks(book) {
        $("tbody").empty();
        for (var i = 0; i < book.length; i++) {
            $("<tr>" +
                "<td>" + book[i].bookName + "</td>" +
                "<td>" + book[i].bookAuthor + "</td>" +
                "<td>" + book[i].bookPublish + "</td>" +
                "<td>" + book[i].bookPage + "</td>" +
                "<td>" + book[i].bookPrice + "</td>" +
                "<td><a name='" + book[i].bookId + "'  title='删除'  >删除</a><a name='" + book[i].bookId + "' title='修改' >修改</a ></td>" +
                "</tr>").appendTo("tbody")
        }
    }
</script>
<html>
<head>
    <title>图书界面</title>
    <%
        String base = request.getContextPath() + "/";
        String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + base;
    %>
    <base href="<%=url%>">
</head>
<body>
<select name="query">
    <option name="" value="-1">请选择</option>
    <option name="" value="1">书名</option>
    <option name="" value="2">作者</option>
    <option name="" value="3">出版社</option>
</select>
<input type="text" name="qval">
<input type="button" value="查询">
<table>
    <thead>
    <tr>
        <td>书名</td>
        <td>作者名字</td>
        <td>出版社</td>
        <td>页数</td>
        <td>价格</td>
        <td>操作
        <td>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>
</body>
</html>
